/**
 * This is the main function for the XOr Crypto module.
 */
package Crypto.xor;
public class Main {

	/**
	 * main class
	 * @param args
	 * 
	 * This is the actual main class for the XOr jar file
	 */
	public static void main(String[] args) {
		try {
			if(args.length == 3 && args[0].compareTo("-e") == 0) {
				/* This segment encrypts a given file without specifing the
				*  output location */
				XOrCrypto.encrypt(args[1], args[2], "encrypted.txt");
			} else if (args.length == 4 && args[0].compareTo("-e") == 0) {
				/* This segment encrypts a given file with the output file
				 * specified */
				XOrCrypto.encrypt(args[1], args[2], args[3]);
			} else if (args.length == 3 && args[0].compareTo("-eS") == 0) {
				/* This segment encrypts a file and prints the string result
				 * to standard out */
				XOrCrypto.encryptStdOut(args[1], args[2]);
			} else if (args.length == 3 && args[0].compareTo("-d") == 0) {
				/* This segment decrypts a given file without specifing the 
				 * output location */
				XOrCrypto.decrypt(args[1], args[2], "decrypted.txt");
			} else if (args.length == 4 && args[0].compareTo("-d") == 0) {
				/* Decrypt and place result at the specified location */
				XOrCrypto.decrypt(args[1], args[2], args[3]);
			} else if (args.length == 3 && args[0].compareTo("-dS") == 0) {
				/* Decrypt and output string to standard out */
				XOrCrypto.decryptStdOut(args[1], args[2]);
			} else if (args.length == 2 && args[0].compareTo("-g") == 0) {
				/* Generate a key */
				XOrCrypto.generateKey(Integer.valueOf(args[1]), "key.txt");
			} else if (args.length == 3 && args[0].compareTo("-g") == 0) {
				/* Generate a key to the given output location */
				XOrCrypto.generateKey(Integer.valueOf(args[1]), args[2]);
			} else if (args.length == 2 && args[0].compareTo("-gS") == 0) {
				/* Generate the key and output to standard out */
				XOrCrypto.generateKeyStdOut(Integer.valueOf(args[1]));
			} else {
				/* If we havent hit any other section, print usage*/
				usageMessage();
			}
		} catch (Exception e) {
			/* Epic fail if you get here */
			e.printStackTrace();
		}
	}

	/**
	 * This is our usage message function
	 */
	public static void usageMessage() {
		System.out.println("Usage: XOr.jar");
		System.out.println("\t-e <filepath> <keypath> [output file]");
		System.out.println("\t-eS <message byte values> <key>");
		System.out.println("\t-d <filepath> <keypath> [output file]");
		System.out.println("\t-dS <cipherText byte values> <key>");
		System.out.println("\t-g <Key Byte Size> [output file]");
		System.out.println("\t-gS <Key Byte Size>");
	}
}
